<?php
namespace appin\cms\model;

use appin\cms\Model;

class Config extends Model
{
    protected $name = 'cms_config';
    protected $globalScope = ['UseLang'];

    /**
     * 获取单个配置文件
     * @param $itemKey
     * @param int $lang_id
     * @return mixed|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function item($itemKey, $lang_id = 0, $default = '')
    {
        $lang_id = !$lang_id ? session('lang.id') : $lang_id;
        $config = static::where('lang_id', $lang_id)->cache(180)->find();
        return isset($config[$itemKey]) ? $config[$itemKey] : $default;
    }
}